﻿using Newtonsoft.Json;
using SimpleTools;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

public class SaveData
{
    public Dictionary<string, bool> CasePass;
    public Dictionary<string, bool> BirdInfo;
    public float muiscSize = 1;
    public float BGMSize = 1;
    public int Size = 5;
    public bool fullScreen = false;
    public string language = "zh";
    public static SaveData _
    {
        get
        {
            if (_m==null)
            {
                _m = SaveData.GetNew();
            }
            return _m;
        }
    }

    private static SaveData _m;
    public static readonly string savePath = @"Save\save";
    private static SaveData GetNew()
    {
        SaveData saveData=new SaveData();
        var saveStr = FileHelp.GetStringData(Application.dataPath+ savePath);
        if (saveStr==null)
        {
            saveData.CasePass = new Dictionary<string, bool>();
            saveData.CasePass.Add("Case1-0", false);
            saveData.CasePass.Add("Case1-2", false);
            saveData.CasePass.Add("Case1-3", false);
            saveData.CasePass.Add("Case1-4", false);
            saveData.CasePass.Add("Case1-5", false);
            saveData.CasePass.Add("Case1-6", false);
            saveData.CasePass.Add("Case1-7", false);
            saveData.CasePass.Add("Case1-8", false);
            saveData.BirdInfo = new Dictionary<string, bool>();
            saveData.BirdInfo.Add("1", false);
            saveData.BirdInfo.Add("2", false);
            saveData.BirdInfo.Add("3", false);
            saveData.BirdInfo.Add("4", false);
            saveData.BirdInfo.Add("5", false);
            saveData.BirdInfo.Add("6", false);
            saveData.BirdInfo.Add("7", false);
            saveData.BirdInfo.Add("8", false);
            saveData.BirdInfo.Add("9", false);
            saveData.BirdInfo.Add("10", true);
        }
        else
        {
            saveData = JsonConvert.DeserializeObject<SaveData>(saveStr);
        }

        //影响界面
        return saveData;
    }

    public void ReadSave()
    {
        EventManager.Invoke("CaseChoosePanel_UpdateUI");
    }

    public static void Save()
    {
        var saveStr = JsonConvert.SerializeObject(_);
        FileHelp.SaveStringData(Application.dataPath + savePath, saveStr);
    }
}
